/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.poligran.polla.mundialista.ingesoft.bean;

import co.com.poligran.polla.mundialista.ingesoft.base.Sala;
import co.com.poligran.polla.mundialista.ingesoft.dao.SalaDAO;
import co.com.poligran.polla.mundialista.ingesoft.impl.SalaImpl;
import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;

/**
 *
 * @author DAVID MOTTA
 */
@ManagedBean (name="beanSala")
@SessionScoped
public class BeanSala extends Sala implements Serializable{
    @ManagedProperty(value="#{navigationBean}")
    private NavigationBean navigationBean;
    public List<Sala> todasSalas = null;
    public Sala salaSelecionada = null;
    public BeanSala(){
        super();
    }
    
   @PostConstruct
    public void init() {
       traerSalas();
    } 
     public void setNavigationBean(NavigationBean navigationBean) {
		this.navigationBean = navigationBean;
	}

    public NavigationBean getNavigationBean() {
        return navigationBean;
    }

    public List<Sala> getTodasSalas() {
        return this.todasSalas;
    }

    public void setTodasSalas(List<Sala> todasSalas) {
        this.todasSalas = todasSalas;
    }

    public Sala getSalaSelecionada() {
        return salaSelecionada;
    }

    public void setSalaSelecionada(Sala salaSelecionada) {
        this.salaSelecionada = salaSelecionada;
    }
    
    
    
    public List<Sala> traerSalas(){    
        SalaDAO salaDao = new SalaImpl();
        todasSalas = new LinkedList();
       return todasSalas = (List) salaDao.selectAll();
    }
    
    public void onRowSelect(SelectEvent event) {
        String strI = String.valueOf(((BeanSala) event.getObject()).getIdSala());
        FacesMessage msg = new FacesMessage("Mesa Seleccionada",strI );
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    // OJO : mensaje pide un string y la variable es de tipo int, tuvo que parsearse 
    public void onRowUnselect(UnselectEvent event) {
        String strI = String.valueOf(((BeanSala) event.getObject()).getIdSala());
        FacesMessage msg = new FacesMessage("Car Unselected", strI);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}
